//
//  ALBaseViewController.swift
//  Swift01
//
//  Created by Miaoyang on 16/4/10.
//  Copyright © 2016年 Miaoyang. All rights reserved.
//

import UIKit



class ALBaseViewController: UITableViewController {
    
    var userLogin = ALUserAccountViewModel.sharedInstance.userLogin
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //根据网络登录
        userLogin ? super.loadView() :setupView()
        
    }
    //定义一个私有方法设置控制器的样式
    private func setupView() {
        
        view = visitorView
        
        visitorView.delegate = self
        
        //添加控制器
        if self is ALHomeTableViewController{
            //让转轮转动
            visitorView.startRotation()
            
        }else if self is ALMessageTableViewController{
            
            visitorView.updataVisitorInfor("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
            
        }else if self is ALDiscroveTableViewController{
            visitorView.updataVisitorInfor("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            
        }else if self is ALProfileTableViewController{
            visitorView.updataVisitorInfor("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        //设置导航栏属性
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(ALBaseViewController.visitorViewDidClickRegisterButton))
        
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(ALBaseViewController.visitorViewDidClickLoginButton))
        
    }
    //懒加载
    //MARK:懒加载
    lazy var visitorView:ALVisitorView = ALVisitorView()
    
    
}
//扩展可以实现协议
extension ALBaseViewController:ALVisitorViewDeleget{
    //注册按钮被点击后的回调方法
    func visitorViewDidClickRegisterButton(){
        
        
    }
    //登录按钮被点击后的回调方法
    func visitorViewDidClickLoginButton(){
        
        let oauthVc = ALOauthViewController()
        //包装导航控制器
        let naVc = UINavigationController(rootViewController:oauthVc)
        
        
        presentViewController(naVc, animated: true, completion: nil)
        
    }
    
}


